package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author fcy
 * @since 2025-09-08
 */
@Slf4j
@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;
    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation(value = "新增分类")
    @PostMapping
    public Result<String> addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }
    /**
     * 分类分页查询
     * @param pageDto
     * @return
     */
    @ApiOperation(value = "分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO  pageDto){
        log.info("分页查询：{}",pageDto);
         return categoryService.queryPage(pageDto);

    }
    /**
     * 删除分类
     * @param id
     * @return
     */
    @ApiOperation(value = "删除分类")
    @DeleteMapping
    public Result<String> delete(Long id) {
        log.info("删除分类：{}",id);
        categoryService.delete(id);
        return Result.success();
    }
    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation(value = "修改分类")
    @PutMapping
    public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改分类：{}",categoryDTO);
        categoryService.change(categoryDTO);
        return Result.success();
    }
    /**
     * 分类状态变更
     * @param status
     * @param id
     * @return
     */
    @ApiOperation(value = "分类状态变更")
    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable Integer status,@RequestParam String id) {
        log.info("状态变更：{}",status);
        categoryService.startOrStop(status,id);
        return Result.success();
    }
    /**
     * 根据类型查询分类
     * @return
     */
    @ApiOperation(value = "根据类型查询分类")
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type) {
        log.info("查询分类：{}",type);
        List<Category> list = categoryService.selectType(type);
        return Result.success(list);
    }


}
